package org.phantom.securityframework.datapermission.internal;

import java.sql.SQLException;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.apache.ibatis.jdbc.SqlRunner;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;

/**
 * 为SimpleSqlDataProvider提供一个数据库访问类
 * @author apple
 *
 */
@Service("myBatisDao")
public class MyBatisDao {

	@Resource
	private SqlSession session;
	private SqlRunner runner;
	
	@PostConstruct
	public void constract() throws SQLException{
		runner = new SqlRunner(session.getConfiguration().getEnvironment().getDataSource().getConnection());
	}
	
	public Object selectList(String mapper,Object para){
		return session.selectList(mapper, para);
	}
	public Object selectOne(String mapper,Object para){
		return session.selectList(mapper, para);
	}
	

	public Object selectList(String sql) throws SQLException{
		Object o = runner.selectAll(sql, new Object[]{});
		return o;
	}
	public Object selectOne(String sql) throws SQLException{
		return runner.selectOne(sql, new Object[]{});
	}
	
}
